package com.ym.b2b.complaint.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.b2b.commons.exception.BaseException;
import com.ym.b2b.commons.service.BaseService;
import com.ym.b2b.complaint.dao.EmBComplaintDAO;
import com.ym.b2b.complaint.service.EmBComplaintService;
import com.ym.b2b.complaint.sqlbean.EmBComplaint;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;

@Service
public class EmBComplaintServiceImpl extends BaseService implements EmBComplaintService {

    @Autowired
    private EmBComplaintDAO complaintDao;

    @Override
    public Result addEmBComplaint(EmBComplaint emBComplaint) throws BaseException {
        Result ret = new Result();
        try {
            complaintDao.insertEmBComplaint(emBComplaint);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            ret.setCodeResult(Result.CODE_100, "新增反馈意见失败。");
        }
        return ret;
    }

    @Override
    public Result searchPageEmBComplaint(EmBComplaint emBComplaint, Page<EmBComplaint> page) {
        Result result = new Result();
        try {
            result.setResultPage(complaintDao.searchPageEmBComplaint(emBComplaint, page));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "查询异常");
        }
        return result;
    }

    @Override
    public int deleteEmBComplaint(Long complaintId) {
        int result = complaintDao.deleteEmBComplaint(complaintId);
        return result;
    }

    @Override
    public int deleteMultipleEmBComplaint(String complaintIdList) {
        int rows = complaintDao.deleteMultipleEmBComplaint(complaintIdList);
        return rows;

    }

    @Override
    public Result updateEmBComplaint(EmBComplaint emBComplaint) {
        Result result = new Result();
        try {
            complaintDao.updateEmBComplaint(emBComplaint);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public Result updateEmBComplaintBat(EmBComplaint emBComplaint) {
        Result result = new Result();
        try {
            complaintDao.updateEmBComplaintBat(emBComplaint);
            result.setResult("修改信息成功!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new BaseException(Result.CODE_100, "修改信息失败!");
        }
        return result;
    }

    @Override
    public EmBComplaint searchEmBComplaint(EmBComplaint emBComplaint) {
        // TODO Auto-generated method stub
        EmBComplaint result = new EmBComplaint();
        result = complaintDao.searchEmBComplaint(emBComplaint.getComplaintId());
        return result;
    }

}
